Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Defining and using visual objects in classes

A class file can use all static visual objects (for example, BROWSE, BUTTON, FRAME, IMAGE, MENU, RECTANGLE, SUB-MENU) as well as STREAM and WORK-TABLE objects, but these can only be defined local to a class file, that is, as PRIVATE data members.

Also, a class file does not support executable code in the main block. The main block can only contain the CLASS statement, DEFINE statements, and ON statements. Typical graphical user interface (GUI) applications have a WAIT-FOR statement or include ON statements within conditional execution pathways. Neither the WAIT-FOR statement nor conditional code is supported within the main block of a class file.

Therefore, when using GUI objects you must follow these restrictions:

  1. An ON statement cannot have any conditional code surrounding its definition.
  2. The WAIT-FOR statement can only be specified in a method or the constructor.
  3. All GUI objects must be implicitly or explicitly defined as PRIVATE.

Given these rules the following class file is valid:

CLASS Driver: 
    DEFINE PRIVATE BUTTON msg. 
    DEFINE PRIVATE BUTTON done. 
    DEFINE FRAME f msg done. 
    ON 'choose':U OF msg IN FRAME f 
    DO: 
        MESSAGE "click" VIEW-AS ALERT-BOX. 
    END. 
    CONSTRUCTOR PUBLIC Driver ( ): 
        ModalDisplay ( ). 
    END CONSTRUCTOR. 
    METHOD PRIVATE VOID ModalDisplay ( ): 
         ENABLE ALL WITH FRAME f. 
         WAIT-FOR CHOOSE OF done. 
    END METHOD. 
END CLASS. 

However, the following class file is invalid, because the lines marked with bold comments (#1 and #2) contain executable code:

CLASS Driver: 
    DEFINE PRIVATE BUTTON msg. 
    DEFINE PRIVATE BUTTON done. 
    DEFINE FRAME f msg done. 
    DEFINE VARIABLE bGraphical AS LOGICAL NO-UNDO. 
/* #1 */  
    IF bGraphical THEN DO: 
        ON 'choose':U OF msg IN FRAME f 
        DO: 
            MESSAGE "click" VIEW-AS ALERT-BOX. 
        END. 
    END. 
    ELSE DO: 
        ON 'choose':U OF msg IN FRAME f 
        DO: 
            PUT "click" TO STREAM outstream. 
        END. 
    END. 
    CONSTRUCTOR PUBLIC Driver ( ): 
        ModalDisplay ( ). 
    END CONSTRUCTOR. 
    METHOD PRIVATE VOID ModalDisplay ( ): 
        ENABLE ALL WITH FRAME f. 
    END METHOD. 
/* #2 */ 
    WAIT-FOR CHOOSE OF done. 
END CLASS. 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095